package com.bishe.controller;

import cn.hutool.core.util.StrUtil;
import com.bishe.dao.UserDao;
import com.bishe.pojo.LoginModel;
import com.bishe.pojo.Message;
import com.bishe.pojo.User;
import com.bishe.serivce.IUserService;
import com.bishe.utils.EcoBootException;
import com.bishe.utils.JobUtil;
import com.bishe.utils.Result;
import com.bishe.utils.SqlQueryUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;


/**
 * 用户控制层
 * @date 2022/2/28 13:52
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户")
@CrossOrigin
public class UserController {

    @Autowired
    private IUserService userService;

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @ApiOperation("登录")
    @PostMapping("/login")
    public Result login(@RequestBody LoginModel loginModel){
        if (loginModel == null){
            throw new EcoBootException("用户名密码为空！");
        }
        if (StrUtil.isEmpty(loginModel.getUserName())||StrUtil.isEmpty(loginModel.getPassWord())){
            throw new EcoBootException("用户名或密码为空！");
        }

        //登录处理
        LoginModel login = userService.login(loginModel);

        return  Result.ok("ok",login);
    }
    @Autowired
    private UserDao userDao;

    @ApiOperation("检查登录")
    @PostMapping("/checkLogin")
    public void checkLogin(HttpServletRequest request){
        JobUtil.checkLogin(request,userDao);
    }


}
